
import base64

def base64_to_img(bstr, file_path):
    if 'data:image/png;base64,' in bstr:
        bstr = bstr.replace('data:image/png;base64,', '')
    if 'data:image/jpg;base64,' in bstr:
        bstr = bstr.replace('data:image/jpg;base64,', '')

    if len(bstr) % 4:
        bstr += '=' * (4 - len(bstr) % 4)

    imgdata = base64.b64decode(bstr)
    file = open(file_path, 'wb')
    file.write(imgdata)
    file.close()

# base64_to_img('',
#                'D:\\tmp\pic\\base64\\jd\\max.jpg')